home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Path Gradient / Setting the Center Point / GDITEST64.dpr
Encoding:
Text File  |  2003-10-15  |  2.9 KB  |  112 lines

  1. program GDITEST64;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   path: TGPGraphicsPath;
  15.   pthGrBrush: TGPPathGradientBrush;
  16.   count: Integer;
  17. const
  18.   colors : array[0..0] of TGPColor = (aclAqua);
  19. begin
  20.   graphics := TGPGraphics.Create(DC);
  21.  
  22.   // Create a path that consists of a single ellipse.
  23.   path:= TGPGraphicsPath.Create;
  24.   path.AddEllipse(0, 0, 140, 70);
  25.  
  26.   // Use the path to construct a brush.
  27.   pthGrBrush:= TGPPathGradientBrush.Create(path);
  28.  
  29.   // Set the center point to a location that is not the centroid of the path.
  30.   pthGrBrush.SetCenterPoint(MakePoint(120, 40));
  31.  
  32.   // Set the color at the center point to blue.
  33.   pthGrBrush.SetCenterColor(MakeColor(255, 0, 0, 255));
  34.  
  35.   // Set the color along the entire boundary of the path to aqua.
  36.   count := 1;
  37.   pthGrBrush.SetSurroundColors(@colors, count);
  38.  
  39.   graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
  40.  
  41.   path.Free;
  42.   pthGrBrush.Free;
  43.   graphics.Free;
  44. end;
  45.  
  46.  
  47. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  48. var
  49.   Handle: HDC;
  50.   ps: PAINTSTRUCT;
  51. begin
  52.   case message of
  53.     WM_PAINT:
  54.       begin
  55.         Handle := BeginPaint(Wnd, ps);
  56.         OnPaint(Handle);
  57.         EndPaint(Wnd, ps);
  58.         result := 0;
  59.       end;
  60.  
  61.     WM_DESTROY:
  62.       begin
  63.         PostQuitMessage(0);
  64.         result := 0;
  65.       end;
  66.  
  67.    else
  68.       result := DefWindowProc(Wnd, message, wParam, lParam);
  69.    end;
  70. end;
  71.  
  72. var
  73.   hWnd     : THandle;
  74.   Msg      : TMsg;
  75.   wndClass : TWndClass;
  76. begin
  77.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  78.    wndClass.lpfnWndProc    := @WndProc;
  79.    wndClass.cbClsExtra     := 0;
  80.    wndClass.cbWndExtra     := 0;
  81.    wndClass.hInstance      := hInstance;
  82.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  83.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  84.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  85.    wndClass.lpszMenuName   := nil;
  86.    wndClass.lpszClassName  := 'GettingStarted';
  87.  
  88.    RegisterClass(wndClass);
  89.  
  90.    hWnd := CreateWindow(
  91.       'GettingStarted',       // window class name
  92.       'Setting the Center Point',       // window caption
  93.       WS_OVERLAPPEDWINDOW,    // window style
  94.       Integer(CW_USEDEFAULT), // initial x position
  95.       Integer(CW_USEDEFAULT), // initial y position
  96.       Integer(CW_USEDEFAULT), // initial x size
  97.       Integer(CW_USEDEFAULT), // initial y size
  98.       0,                      // parent window handle
  99.       0,                      // window menu handle
  100.       hInstance,              // program instance handle
  101.       nil);                   // creation parameters
  102.  
  103.    ShowWindow(hWnd, SW_SHOW);
  104.    UpdateWindow(hWnd);
  105.  
  106.    while(GetMessage(msg, 0, 0, 0)) do
  107.    begin
  108.       TranslateMessage(msg);
  109.       DispatchMessage(msg);
  110.    end;
  111. end.
  112.